
#include <sys/socket.h>
#include <glib.h>
#include <fcntl.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <assert.h>
#include <sstream>
#include <string>
#include "Defines.h"
#include "Facade.h"
#include "panda.h"
#include "Threads.h"
#include "SockHandler.h"
#include "define.h"
#include "Debug.h"
#include "Helper.h"

using namespace std;

int MemHandler :: ReadProcess(conn *c)
{
	Facade *pR = Facade::Instance();
	Helper *p = Helper::Instance();
	unsigned int uint_len = sizeof(unsigned);
	int iret = PANDA_ERROR_SYSTEM;
	//unsigned retBlen = 0;
        //char *retBuf = NULL;
	if(c->rbytes >= uint_len)   // imethod + ihash + ?
	{
		unsigned imethod;
		char *pChar = (char*)c->rcurr;
		unsigned ilen = 0;
		bcopy(pChar, &imethod, uint_len);
		ilen += uint_len;
		DEBUG2("c->rbytes = ", c->rbytes);
		if( imethod > 0 && imethod < 10)
  	            iret = p->Do_Method(imethod, pChar+ilen, c->rbytes-uint_len, &(c->wbuf), c->wsize, c->wbytes);
        }
        pR->GetNetWork()->write_block(c) ; //, retBuf, retBlen);
        
	return conn_read; // closing;
}

int MemHandler :: WriteProcess(conn *c)
{
	return conn_closing;
}


